﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sort
{
    static class BubbleSort
    {
        static void Main()
        {
            int[] arr = { 1, 2, 3, 5, 0, 9, 8, 7, 6, 4 };
            Random rd = new Random();
            for (int j = 0; j < 100000; j++)
            {
                for (int i = 0; i < 10; i++)
                {
                    arr[i] = rd.Next(20);
                }
                Sort(arr);
                if (!Utils.CheckOrderArray(arr))
                {
                    Console.WriteLine("error.");
                }
                //Utils.WriteArr(arr);
            }
        }

        public static void Sort(int[] arr)
        {

            for (int i = 0; i < arr.Length; i++)
            {
                bool bSwap = false;
                for (int j = 1; j < arr.Length - i; j++)
                {
                    if (arr[j] < arr[j - 1])
                    {
                        Utils.Swap(arr, j, j - 1);
                        bSwap = true;
                    }
                }
                if (!bSwap)
                {
                    break;
                }
            }
        }
    }
}
